﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ApplicationBoom.Command;
namespace ApplicationBoom.ViewModel
{
    class MainWindow : Base.BaseObject
    {

        public MainWindow()
		{
			m_AsyncSimulationTimer = new System.Timers.Timer(1);
			m_AsyncSimulationTimer.Elapsed += (s, e) =>
			{
				m_Index += 1;
				Children.Add(new DataModel.SimpleDataObject {
					Text = "Text",
					Index = m_Index,
                    Description = "Text"
				});

			};
		}
        private System.Timers.Timer m_AsyncSimulationTimer;

        private long m_Index;
        public DataModel.SimpleDataObject TextObject
        {
            get
            {
                if (m_TextObject == null)
                {
                    m_TextObject = new DataModel.SimpleDataObject();
                }
                return m_TextObject;
            }
            set
            {
                m_TextObject = value;
                OnPropertyChanged("TextObject");
            }
        }
        private static object _lock = new object();
        private DataModel.SimpleDataObject m_TextObject;
        public System.Collections.ObjectModel.ObservableCollection<DataModel.SimpleDataObject> Children
        {
            get
            {
                if (m_Children == null)
                {
                    m_Children = new System.Collections.ObjectModel.ObservableCollection<DataModel.SimpleDataObject>();
                    System.Windows.Data.BindingOperations.EnableCollectionSynchronization( m_Children, _lock);
                  }
                return m_Children;
            }
        }


        private System.Collections.ObjectModel.ObservableCollection<DataModel.SimpleDataObject> m_Children;


        public RelayCommand StartTimerCommand
        {
            get
            {
                if (m_StartTimerCommand == null)
                {
                    m_StartTimerCommand = new RelayCommand(param => m_AsyncSimulationTimer.Start());
                }
                return m_StartTimerCommand;
            }
        }

        private RelayCommand m_StartTimerCommand;


        public RelayCommand StopTimerCommand
        {
            get
            {
                if (m_StopTimerCommand == null)
                {
                    m_StopTimerCommand = new RelayCommand(param => m_AsyncSimulationTimer.Stop());
                }
                return m_StopTimerCommand;
            }
        }
        private RelayCommand m_StopTimerCommand;
    }
}
